package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//`@ControllerAdvice`用于声明处理全局Controller方法异常的类
@ControllerAdvice
public class GlobalExceptionHandler {

    //注解表明该方法要捕获的异常
    @ExceptionHandler(Exception.class)
    //ResponseBody返回数据
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(leaseException.class)
    //ResponseBody返回数据
    @ResponseBody
    public Result error(leaseException e){
        e.printStackTrace();
        return Result.fail(e.getCode(), e.getMassage());
    }
}